package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.PackingDao;
import cn.itcast.domain.cargo.Packing;
import cn.itcast.domain.cargo.PackingExample;
import cn.itcast.service.cargo.PackingService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service  //dubbo
public class PackingServiceImpl implements PackingService {

    @Autowired
    PackingDao packingDao;

    //条件查询
    @Override
    public List<Packing> findAll(PackingExample packingExample) {
        return packingDao.selectByExample(packingExample);
    }

    //分页查询
    @Override
    public PageInfo findAll(int page, int size, PackingExample example) {
        //设置分页参数
        PageHelper.startPage(page,size);

        //查询所有
        //使用PageInfo包装上面的list
        return new PageInfo(packingDao.selectByExample(example));
    }

    //根据id查询所有
    @Override
    public Packing findById(String id) {
        return packingDao.selectByPrimaryKey(id);
    }

    //根据id删除
    @Override
    public void deletById(String id) {
        //1.获取装箱单对象
        Packing packing = packingDao.selectByPrimaryKey(id);
        //2.获取装箱单状态
        int i = Integer.valueOf(packing.getState()).intValue();
        if (i == 1){
            packingDao.deleteByPrimaryKey(id);
        }else {
            return ;
        }

    }





    @Override
    public void save(Packing packing) {

    }

    @Override
    public void update(Packing packing) {

    }









}
